package cwb1;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * 
 * @author Aurora
 *
 */
public abstract class Division implements Data {
	//amount of fields, without lists sended to the database.
	private static final long AMOUNT_OF_IMPORTANT_FIELDS = 2;
	
	private static final String KIND = "Division";
	
	//Mag geen spaties bevatten !!!!!!!!!!
	private String divisionId;
	private long divisionType;
	
	private ArrayListMap<String> students;
	
	public Division(String divisionId, long divisionType) {
		students = new ArrayListMap<String>();
		this.divisionId = divisionId;
		this.divisionType = divisionType;
	}
	
	public Division(Map<String, Object> properties) {
		students = new ArrayListMap<String>(properties, properties.size() - getAmountOfFields() - AMOUNT_OF_IMPORTANT_FIELDS);
		divisionId = (String) properties.get("divisionId");
		divisionType = (Long) properties.get("divisionType");
	}
		
	public HashMap<String, Object> getProperties() {
    	HashMap<String,Object> properties = new HashMap<String, Object>(students.getProperties());
    	properties.put("divisionId", divisionId);
    	properties.put("divisionType", divisionType);
    	
    	
    	return properties;
    }
	
	public abstract int getAmountOfFields();
	
	protected void setDivisionType(long divisionType) {
		this.divisionType = divisionType;
	}
	
	public long getDivisionType()
	{
		return divisionType;
	}
	
	/**
     * Adds a user to this course.
     * @param user The user to be added.
     */
    public void addUserToCourse(User user) {
    	students.add(user.getId());
    }
    
    /**
     * Returns all the userIds who are enlist to this course.
     * @return the users enlisted to this course.
     */
    public List<String> getStudentsId() {
    	return students;
    }
    
    /**
     * Removes the user of this course
     * @param user The user to be removed.
     */
    public void removeUser(User user) {
    	students.remove(user.getId());
    }
    
    public String getKind() {
    	return KIND;
    }
    
    public static String staticGetKind()
	{
		return KIND;
	}
    
    public String getId() {
    	return divisionId;
    }
    
    public boolean equals(Division division) {
    	return divisionId.equals(division.getId());
    }
    
    public boolean checkStudent(String userId)
    {
    	boolean found = false;
    	Iterator<String> it = students.iterator();
    	while(it.hasNext()){
            String checker = it.next();
            if(checker.equals(userId))
            {
            	found = true;
            }
    	}
    	return found;
    }
}
